// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-12-16

package counter

import (
	"sync/atomic"
)

type (
	MqCounter interface {
		GetAcknowledgedCount() int64
		GetDiscardedCount() int64
		GetFailProducedCount() int64
		GetFailScheduledCount() int64
		GetPopCount() int64
		GetProducedCount() int64
		GetPushCount() int64
		GetReceivedCount() int64
		GetScheduledCount() int64
		GetSuccessProducedCount() int64
		GetSuccessScheduledCount() int64

		IncrAcknowledgedCount(n int64)
		IncrDiscardedCount(n int64)
		IncrPopCount(n int64)
		IncrProducedCount(n int64)
		IncrPushCount(n int64)
		IncrReceivedCount(n int64)
		IncrScheduledCount(n int64)
		IncrFailProducedCount(n int64)
		IncrFailScheduledCount(n int64)
		IncrSuccessProducedCount(n int64)
		IncrSuccessScheduledCount(n int64)
	}

	mq struct {
		AcknowledgedCount    int64
		ReceivedCount        int64
		ProducedCount        int64
		FailProducedCount    int64
		SuccessProducedCount int64
		PushCount            int64
		PopCount             int64

		DiscardedCount        int64
		ScheduledCount        int64
		FailScheduledCount    int64
		SuccessScheduledCount int64
	}
)

func (o *mq) GetAcknowledgedCount() int64     { return atomic.LoadInt64(&o.AcknowledgedCount) }
func (o *mq) GetDiscardedCount() int64        { return atomic.LoadInt64(&o.DiscardedCount) }
func (o *mq) GetFailProducedCount() int64     { return atomic.LoadInt64(&o.FailProducedCount) }
func (o *mq) GetFailScheduledCount() int64    { return atomic.LoadInt64(&o.FailScheduledCount) }
func (o *mq) GetPopCount() int64              { return atomic.LoadInt64(&o.PopCount) }
func (o *mq) GetProducedCount() int64         { return atomic.LoadInt64(&o.ProducedCount) }
func (o *mq) GetPushCount() int64             { return atomic.LoadInt64(&o.PushCount) }
func (o *mq) GetReceivedCount() int64         { return atomic.LoadInt64(&o.ReceivedCount) }
func (o *mq) GetScheduledCount() int64        { return atomic.LoadInt64(&o.ScheduledCount) }
func (o *mq) GetSuccessProducedCount() int64  { return atomic.LoadInt64(&o.SuccessProducedCount) }
func (o *mq) GetSuccessScheduledCount() int64 { return atomic.LoadInt64(&o.SuccessScheduledCount) }

func (o *mq) IncrAcknowledgedCount(n int64)     { atomic.AddInt64(&o.AcknowledgedCount, n) }
func (o *mq) IncrDiscardedCount(n int64)        { atomic.AddInt64(&o.DiscardedCount, n) }
func (o *mq) IncrFailProducedCount(n int64)     { atomic.AddInt64(&o.FailProducedCount, n) }
func (o *mq) IncrFailScheduledCount(n int64)    { atomic.AddInt64(&o.FailScheduledCount, n) }
func (o *mq) IncrPopCount(n int64)              { atomic.AddInt64(&o.PopCount, n) }
func (o *mq) IncrProducedCount(n int64)         { atomic.AddInt64(&o.ProducedCount, n) }
func (o *mq) IncrPushCount(n int64)             { atomic.AddInt64(&o.PushCount, n) }
func (o *mq) IncrReceivedCount(n int64)         { atomic.AddInt64(&o.ReceivedCount, n) }
func (o *mq) IncrScheduledCount(n int64)        { atomic.AddInt64(&o.ScheduledCount, n) }
func (o *mq) IncrSuccessProducedCount(n int64)  { atomic.AddInt64(&o.SuccessProducedCount, n) }
func (o *mq) IncrSuccessScheduledCount(n int64) { atomic.AddInt64(&o.SuccessScheduledCount, n) }

func (o *mq) init() *mq {
	return o
}
